<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use DB;

class WarehouseOutbound extends Model
{
    protected $table = 'warehouse_outbound';
    public static function getorders($id){
        /*$count = 11-mb_strlen($id);
        $j=9;
        $h=1;
        for ($i=2;$i<=$count;$i++){
            $c = 9;
            $hh = 1;
            $j = $j.$c;
            $h = $h.$hh;
        }
        return 'CK'.mt_rand($h,$j).$id;*/
        return 'CK'.time().mt_rand(1111,9999);
    }

    /**
     * 出库类型：1：领用出库；2：盘点出库：3：报废出库
     * @param $type
     * @return string|string[]
     */
    public static function get_outbound_type($type=0){
        $data = ['1'=>'领用出库','2'=>'盘点出库','3'=>'报废出库'];
        return $data[$type]??$data;
    }

    public function warehouseOutboundDetail()
    {
        return $this->hasMany('App\Model\WarehouseOutboundDetail','outbound_id');
    }

    //申请人
    public function Users()
    {
        return $this->belongsTo('App\Model\Users','user_id');
    }
}
